#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

int main()
{
    LL a, da, b, db;
    cin >> a >> da >> b >> db;
    
    LL ans1 = 0, ans2 = 0;
    while(a)
    {
        if(a % 10 == da)
        {
            ans1 = ans1 * 10 + da;
        }
        a /= 10;
    }
    
    while(b)
    {
        if(b % 10 == db)
        {
            ans2 = ans2 * 10 + db;
        }
        
        b /= 10;
    }
    
    cout << ans1 + ans2 << endl;
    return 0;
}